;

// 封装回到顶部功能的函数
function initBackToTop(id) {
    // 获取元素
    var $backToTop = $('#'+id);

    // 显示/隐藏回到顶部按钮
    function toggleBackToTop() {
        // 当滚动距离超过300px时显示按钮，否则隐藏
        // window.pageYOffset > 300
        // $(window).scrollTop() > 300
        if ($(window).scrollTop() > 300) {
            $backToTop.addClass('show');
        } else {
            $backToTop.removeClass('show');
        }
    }

    // 回到顶部动画
    function scrollToTop() {
        // 使用动画效果平滑滚动到顶部
        $('html, body').animate({
            scrollTop: 0
        }, 500); // 500ms的动画时长
    }

    // 初始化时检查一次
    toggleBackToTop();

    // 监听滚动事件
    $(window).on('scroll', toggleBackToTop);

    // 点击事件
    $backToTop.on('click', scrollToTop);

    // 返回公共方法（可选，用于外部调用）
    return {
        show: function() {
            $backToTop.addClass('show');
        },
        hide: function() {
            $backToTop.removeClass('show');
        },
        scrollToTop: scrollToTop
    };
}


// 初始化所有轮播
// initCarousel('.carousel', 3000)
function initCarousel(element, interval = 3000) {
    const carousels = document.querySelectorAll(element);
    carousels.forEach(carousel => {
        new bootstrap.Carousel(carousel, {
            interval: interval, // 5秒自动切换
            wrap: true, // 循环播放
            keyboard: true // 支持键盘控制
        });
    });
}

// 通知提示功能
//showNotification('这是类似layer的操作提示！', 10);
function showNotification(message, time = 3) {
    // 检查是否已有通知元素
    let notification = document.querySelector('.floating-notification');

    // 如果没有则创建
    if (!notification) {
        notification = document.createElement('div');
        notification.className = 'floating-notification';
        notification.style.position = 'fixed';
        //notification.style.bottom = '20px';
        //notification.style.right = '20px';
        notification.style.top = '50%';
        notification.style.left = '50%';
        notification.style.color = 'white';
        notification.style.textAlign = 'center';
        notification.style.minWidth = '150px';
        notification.style.backgroundColor = 'gray';
        notification.style.borderRadius = '8px';
        notification.style.boxShadow = '0 4px 12px rgba(0,0,0,0.15)';
        notification.style.padding = '12px 16px';
        notification.style.zIndex = '1000';
        notification.style.transition = 'all 0.3s ease';
        notification.style.transform = 'translateY(100px)';
        notification.style.opacity = '0';
        document.body.appendChild(notification);
    }

    // 设置消息内容并显示
    notification.textContent = message;
    notification.style.transform = 'translateY(0)';
    notification.style.opacity = '1';

    // 3秒后隐藏
    setTimeout(() => {
        notification.style.transform = 'translateY(100px)';
        notification.style.opacity = '0';
    }, time * 1000);
}



